package cn.jmz.micpro.common.result;

import cn.jmz.micpro.common.exception.DefinitionException;
import lombok.Data;

@Data
public class GlobalResult<T>{

    private String code;
    private String msg;
    private T data;

    public GlobalResult(){

    }

    public GlobalResult(String code, String msg){
        this.code = code;
        this.msg = msg;
    }

    //自定义返回结果的构造方法
    public GlobalResult(String code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //自定义异常返回的结果
    public static GlobalResult defineError(DefinitionException de){
        GlobalResult result = new GlobalResult();
        result.setCode(de.getErrorCode());
        result.setMsg(de.getErrorMsg());
        result.setData(null);
        return result;
    }

}
